# -------------------------------------------------------------------------------
# Description:  
# Reference:
# Name:   relaxtionTransfer
# Author: wujun
# Date:   2021-12-15
# -------------------------------------------------------------------------------
import json
import os

def findAllAtrributes(filePath):
    filelist = os.listdir(filePath)
    attributesList = []
    for file in filelist:
        filePath = r'D:\protegeAuto_tool\JsonCenter\event\\' + str(file)
        # 读取json文件内容,返回字典格式
        with open(filePath,'r',encoding='utf-8')as fp:
            json_data = json.load(fp)
            oneList = list(set(list(json_data['attributes'].keys())))
            for i in oneList:
                if(i in attributesList):
                    pass
                else:
                    attributesList.append(i)
        fp.close()
    return attributesList

def attrribute2relaxtion(filePath,attrribute,relaxtion):
    filelist = os.listdir(filePath)
    for file in filelist:
        try:
            filePath = r'D:\protegeAuto_tool\JsonCenter\event\\' + str(file)
            # 读取json文件内容,返回字典格式
            with open(filePath, 'r', encoding='utf-8')as fp:
                json_data = json.load(fp)
                attributesDic = json_data['attributes']
                if(attrribute in list(attributesDic.keys())):
                    if("，" in attributesDic[attrribute]):
                        json_data['relation'][relaxtion] = attributesDic[attrribute].split('，')
                    elif("、" in attributesDic[attrribute]):
                        json_data['relation'][relaxtion] = attributesDic[attrribute].split('、')
                    elif ("；" in attributesDic[attrribute]):
                        json_data['relation'][relaxtion] = attributesDic[attrribute].split('；')
                    else:
                        json_data['relation'][relaxtion] = [attributesDic[attrribute]]

                print(json_data)
            fp.close()
            with open(filePath, 'w', encoding='utf-8') as json_file:
                json_str = json.dumps(json_data, indent=4, ensure_ascii=False)
                json_file.write(json_str)
            print("{}已update".format(filePath))
        except:
            print("{}无法解析".format(file))
            pass


# allAtrributes = findAllAtrributes(r'D:\protegeAuto_tool\JsonCenter\event')
# print(allAtrributes)
filePath = r'D:\protegeAuto_tool\JsonCenter\event'
attrribute2relaxtion(filePath,'时间',"开始时间")
attrribute2relaxtion(filePath,'地点',"事件地点")
attrribute2relaxtion(filePath,'别名',"别名")
attrribute2relaxtion(filePath,'发生地点',"事件地点")
attrribute2relaxtion(filePath,'发生时间',"开始时间")
attrribute2relaxtion(filePath,'又称',"别名")
attrribute2relaxtion(filePath,'主要指挥官',"相关人物")
attrribute2relaxtion(filePath,'领导机构',"相关组织机构")
attrribute2relaxtion(filePath,'参战方',"相关组织机构")
attrribute2relaxtion(filePath,'发生时间 ',"开始时间")
attrribute2relaxtion(filePath,'发生时间  ',"开始时间")
attrribute2relaxtion(filePath,'领导者',"相关人物")
attrribute2relaxtion(filePath,'结束时间',"结束时间")
attrribute2relaxtion(filePath,'组织机构',"相关组织机构")
attrribute2relaxtion(filePath,'开始时间',"开始时间")
attrribute2relaxtion(filePath,'主要人员',"相关人物")
attrribute2relaxtion(filePath,'主要领导人',"相关人物")
attrribute2relaxtion(filePath,'参战军队',"相关组织机构")
attrribute2relaxtion(filePath,'相关人物',"相关人物")
attrribute2relaxtion(filePath,'战争导火索',"相关事件")
attrribute2relaxtion(filePath,'暴动地点',"事件地点")
attrribute2relaxtion(filePath,'暴动时间',"开始时间")
attrribute2relaxtion(filePath,'领导人',"相关人物")
attrribute2relaxtion(filePath,'发生国家',"相关组织机构")
attrribute2relaxtion(filePath,'举办时间',"事件地点")
attrribute2relaxtion(filePath,'相关文件',"相关文件")
attrribute2relaxtion(filePath,'主要人物',"相关人物")
attrribute2relaxtion(filePath,'发起人',"相关人物")
attrribute2relaxtion(filePath,'地方',"事件地点")
attrribute2relaxtion(filePath,'起义时间',"开始时间")
attrribute2relaxtion(filePath,'相关事件',"相关事件")
attrribute2relaxtion(filePath,'领导',"相关组织机构")
attrribute2relaxtion(filePath,'地址',"事件地点")
attrribute2relaxtion(filePath,'相关会议',"相关会议")
attrribute2relaxtion(filePath,'人物',"相关人物")
attrribute2relaxtion(filePath,'地区',"事件地点")
attrribute2relaxtion(filePath,'代表人物',"相关人物")
attrribute2relaxtion(filePath,'中央代表',"相关人物")
attrribute2relaxtion(filePath,'地方代表',"相关人物")
attrribute2relaxtion(filePath,'中央代表',"相关人物")
attrribute2relaxtion(filePath,'领导阶级派别',"相关组织机构")
attrribute2relaxtion(filePath,'重要城市',"事件地点")
attrribute2relaxtion(filePath,'主要战役',"相关事件")
attrribute2relaxtion(filePath,'省份',"事件地点")
attrribute2relaxtion(filePath,'共产党指挥官',"相关人物")
attrribute2relaxtion(filePath,'地 点',"事件地点")
attrribute2relaxtion(filePath,'签订条约',"相关文件")
attrribute2relaxtion(filePath,'组织',"相关组织机构")
attrribute2relaxtion(filePath,'签订条约',"相关文件")
attrribute2relaxtion(filePath,'爆发时间',"开始时间")
attrribute2relaxtion(filePath,'会议地点',"事件地点")
attrribute2relaxtion(filePath,'出席成员',"相关人物")
attrribute2relaxtion(filePath,'谈判方',"相关组织机构")
attrribute2relaxtion(filePath,'副大队长',"相关人物")
attrribute2relaxtion(filePath,'大队长',"相关人物")
attrribute2relaxtion(filePath,'大队长',"相关人物")

